home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / RTF / textrect.h < prev    next >
C/C++ Source or Header  |  1994-08-01  |  4KB  |  167 lines

  1. /* $Header: /usr/people/pcd/Src/RTF/RCS/textrect.h,v 1.1 92/11/23 12:58:52 pcd Exp Locker: pcd $
  2.  */
  3.  
  4. #ifndef __textrect_h
  5. #define __textrect_h
  6.  
  7. #include "textflow.h"
  8.  
  9. #define implies(p,q) assert(!(p) || (q))
  10.  
  11.  
  12.  
  13. class Box{
  14.   friend class LRBox; // for destroy
  15. public:
  16.   Box(Box* prev);
  17.   ~Box()
  18.     { delete prev_; };
  19.  
  20.   TextPosition  position(const Extent&);
  21.   TextPosition  format(const TextFlow*, TextPosition, TextPosition,
  22.                Extent, Extent&, int word_wrap = 0);
  23.   void          render(const BRect&);
  24.   Coord         locate(TextPosition, Coord, Coord) const;
  25.  
  26.   Box* prev()
  27.     { return prev_; };
  28.   void      x(Coord xx, Coord w)
  29.     { location.x = xx; width = w; };
  30.   void      y(Coord yy); // affects prev
  31.   void      move(Coord dx); // affects prev
  32.   Coord     left()
  33.     { return location.x; };
  34.   Coord     right()
  35.     { return location.x + width; };
  36.  
  37.   TextPosition first() const
  38.     { return f; }
  39.  
  40. protected:
  41.   Box* destroy()
  42.     { Box* p = prev_; prev_ = 0; delete this; return p; };
  43. private:
  44.   Box* prev_;
  45.   TextPosition f;
  46.   TextPosition first_;
  47.   const TextFlow* formnode;
  48.   Qty bytes;
  49.   Point location;
  50.   Coord width;
  51. };
  52.  
  53. class LRBox{
  54.   friend class TextRect; // for destroy
  55. public:
  56.   LRBox(LRBox* prev);
  57.   ~LRBox()
  58.     { delete runs; delete prev_; };
  59.  
  60.   TextPosition format(const TextFlow*, TextPosition, TextPosition,
  61.               Extent, Extent&, int just=-1);
  62.   /* USE : pos = lrbox->format(flow, first, last, avail, used);
  63.    *       assert(pos >= first && pos <= last);
  64.    */
  65.  
  66.   void      render(const BRect&);
  67.  
  68.   TextPosition  position(Coord);
  69.  
  70.   Coord         locate(TextPosition) const;
  71.  
  72.   TextPosition  first()
  73.     { return f; };
  74.  
  75.   Coord      y0() const
  76.     { return y0_; };
  77.   LRBox* prev() const
  78.     { return prev_; };
  79.   Coord     top() const
  80.     { return y0_; };
  81.   Coord     bottom() const
  82.     { return y0_ + ascent + descent; };
  83.   Coord     height() const
  84.     { return ascent + descent; };
  85.  
  86. protected:
  87.   LRBox* destroy()
  88.     { LRBox* p = prev_; prev_ = 0; delete this; return p; };
  89. private:
  90.   LRBox* prev_;
  91.   Box* runs;
  92.   Coord y0_;
  93.   Coord ascent, descent;
  94.   TextPosition f;
  95. };
  96.  
  97.  
  98. class TextRect{
  99.   /************
  100.    *
  101.    * A TextRect formats and renders information from a TextFlow.
  102.    *
  103.    ************/
  104.  
  105. public:
  106.   TextRect();
  107.   /* USE : assert(textrect->region(first, last) < textrect->bounds());
  108.    *******/
  109.  
  110.   ~TextRect()
  111.     { delete lines; };
  112.  
  113.   /*******/
  114.   TextPosition
  115.     format(const TextFlow* tree, Qty first, Qty last,
  116.        const BRect& available);
  117.   /* DESC: compute sizes and positions of information from a TextFlow
  118.    * USE : assert(first <= last);
  119.    *       last_formatted = textrect->format(tree, first, last, available);
  120.    *       assert(first <= last_formatted);
  121.    *       assert(last_formatted <= last);
  122.    *       assert(textrect->bounds() <= available);
  123.    * @#BRect: x,y,w,h >= 0
  124.    * TIME: O(last-first) x TIME(TextFlow::character_shape())
  125.    *******/
  126.  
  127.   /*******/
  128.   const BRect&
  129.     bounds() { return bounds_; };
  130.   /*
  131.    ******/
  132.  
  133.   /*******/
  134.   void
  135.     render(const BRect& exposed);
  136.   /* USE : textrect->render(exposed);
  137.    * TIME: @#
  138.    *******/
  139.  
  140.   /***********/
  141.   TextPosition 
  142.     position(Coord x, Coord y);
  143.   /* USE : pos = textrect->position(x, y);
  144.    * TIME: @#
  145.    ***********/
  146.  
  147.   /*******/
  148.   Coord
  149.     locate(TextPosition here, Coord* top=0, Coord* bottom=0) const;
  150.   /* USE : int x = textrect->locate(here, &top, ⊥
  151.    *       assert(top<=bottom);
  152.    *       int xx,yy; // FORALL
  153.    *       TextPosition p = textrect->position(xx,yy);
  154.    *       implies(yy<top, p<here);
  155.    *       implies(yy>=bottom, p<here);
  156.    *       implies(top<=yy&&yy<=bottom,
  157.    *               xx<x == p<x);
  158.    *               
  159.    *******/
  160.  
  161. private:
  162.   class LRBox* lines;
  163.   BRect bounds_;
  164. };
  165.  
  166. #endif
  167.